back to Creeper World
# Immortal-Tower.crpl
# Created by: nathanaelps
# Created on: 8/28/2020 12:04:36 PM
# ------------------------------------------

$SporeCount:2
$SporeDelay:100 #seconds
$SporeHealthMin:1
$SporeHealthMax:5
$SporePayloadMin:-100
$SporePayloadMax:100
$MaxDepth:-1
$MaxRange:-1
$FloodDepth:1

$IsFlipped:0
$Unhatch:0

once @initialize endonce

getTimer0 eq0 if
  <-Unhatch if @unhatch endif
  <-IsFlipped not if
    @checkForFlip
  else
    <-IsDead if
      CurrentCoords 0 SetCreeperMax
      @shouldWeRaise
    else
      @shouldWeKill
    endif
  endif
  10 SetTimer0
endif

getTimer1 eq0 if
  <-IsDead not
    <-SporeDelay 0 RandInt 1 eq and if @spawnSpore endif
  30 SetTimer1
endif

#-------------------------------

:initialize
  #ShowTraceLog
  0 @setDead
  @setName
  Self CONST_NULLIFIERDAMAGES 0 SetUnitAttribute
  Self CONST_CREATEPZ 0 SetUnitAttribute
  <-IsFlipped if 1 @setIsFlipped endif

:updateImage
  24 ->ImageId
  Self "main" 1.3 1.3 SetImageScale
  <-IsFlipped if <-ImageId 2 add ->ImageId endif
  <-IsDead if <-ImageId 1 add ->ImageId endif
  Self "main" "Custom" <-ImageId Concat SetImage

:setName
  <-SporeCount " max spores, produced every " <-SporeDelay "s" Concat Concat Concat SetPopupText






:checkForFlip
  CurrentCoords GetCreeper 0 <-FloodDepth sub lt ->flooded
  <-flooded if 1 @setIsFlipped endif

:shouldWeRaise
  CurrentCoords GetCreeper 0 <-FloodDepth sub lt ->flooded
  <-flooded not if 0 @setDead endif

:shouldWeKill
  CurrentCoords GetCreeper 0 <-FloodDepth sub lt ->flooded
  <-IsFlipped <-flooded and if 1 @setDead endif


:setDead
  ->IsDead
  @updateImage
  Self CONST_COUNTSFORVICTORY <-IsDead not SetUnitAttribute

:setIsFlipped
  ->IsFlipped
  #<-IsFlipped not @setDead


:unhatch
  "CRPLCORE" CurrentCoords CreateUnit ->unit
  <-unit "Immortal-TowerEgg.crpl" AddScriptToUnit
  <-unit "Immortal-TowerEgg.crpl" "SporeCount" <-SporeCount SetScriptVar
  <-unit "Immortal-TowerEgg.crpl" "SporeDelay" <-SporeDelay SetScriptVar
  <-unit "Immortal-TowerEgg.crpl" "SporeHealthMin" <-SporeHealthMin SetScriptVar
  <-unit "Immortal-TowerEgg.crpl" "SporeHealthMax" <-SporeHealthMax SetScriptVar
  <-unit "Immortal-TowerEgg.crpl" "SporePayloadMin" <-SporePayloadMin SetScriptVar
  <-unit "Immortal-TowerEgg.crpl" "SporePayloadMax" <-SporePayloadMax SetScriptVar
  <-unit "Immortal-TowerEgg.crpl" "MaxRange" <-MaxRange SetScriptVar
  <-unit "Immortal-TowerEgg.crpl" "MaxDepth" <-MaxDepth SetScriptVar
  <-unit "Immortal-TowerEgg.crpl" "FloodDepth" <-FloodDepth SetScriptVar
  Self 0 Destroy




:spawnSpore
  <-isDead not #if
    <-MaxDepth 0 gt CurrentCoords GetCreeper <-MaxDepth lt and and if
    <-SporeCount 0 do

      <-MaxRange 0 gt if
        CurrentCoords <-MaxRange GetUnitsInRange ->unitCount

        <-MaxRange "randomUnit" <-unitCount trace3
        <-unitCount neq0 if
          0 <-unitCount RandInt ->WantedUnit

          <-unitCount 0 do
            I <-WantedUnit eq if ->unit else ->discard endif
          loop

          CurrentCoords <-unit CONST_COORDX GetUnitAttribute <-unit CONST_COORDY GetUnitAttribute
            <-SporeHealthMin <-SporeHealthMax RandInt # -->
            <-SporePayloadMin <-SporePayloadMax RandInt # -->
            CreateSpore
        endif
      else
        CurrentCoords RandUnitCoords
          <-SporeHealthMin <-SporeHealthMax RandInt # -->
          <-SporePayloadMin <-SporePayloadMax RandInt # -->
          CreateSpore
      endif
    loop
  endif